Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <body> <p>Press any key on the keyboard in the input field to get the Unicode character code and the Unicode key code of the pressed key.</p> <p><strong>Note:</strong> The which and keyCode property does not work on the onkeypress event for non-printable, function keys (like CAPS LOCK, CTRL, ESC, F12, etc.).</p> <input type="text" size="50" onkeypress="uniCharCode(event)" onkeydown="uniKeyCode(event)"> <p>onkeypress - <span id="demo"></span></p> <p>onkeydown - <span id="demo2"></span></p> <script> function uniCharCode(event) { var char = event.which || event.keyCode; document.getElementById("demo").innerHTML = "The Unicode CHARACTER code is: " + char; } function uniKeyCode(event) { var key = event.which || event.keyCode; document.getElementById("demo2").innerHTML = "The Unicode KEY code is: " + key; } </script> </body> <!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_event_key_which2 by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:30:44 GMT --> </html>
Result:
Try it Yourself - © w3schools.com